﻿using System;
using System.Windows.Media;

using Game.Map;
using Game.Controller;
using Game.Map.Extensions;

namespace Game.Surface
{
    public class SurfaceField : AbstractField
    {
        readonly AbstractField _surfaceTopField;
        readonly AbstractField _cloudField;

        public SurfaceField(
            IMapFieldView field,
            AbstractField topField,
            AbstractField cloud)
            : base(field)
        {
            _surfaceTopField = topField;
            _cloudField = cloud;

            field.Changed += (source, args) => UpdateBitmap(field);
            field.ViewX().Changed += (source, args) => UpdateBitmap(field);
            field.VehicleX().VehicleAssigned += (source, args) => UpdateBitmap(field);
            field.ObjectX().ObjectAssigned += (source, args) => UpdateBitmap(field);
            if (field.ObjectX().GameObject != null)
            {
                field.ObjectX().GameObject.PlayerChanged += (source, args) =>
                                                                {
                                                                    UpdateBitmap(field);
                                                                };
            }
        }

        public AbstractField SurfaceTopField
        {
            get { return _surfaceTopField; }
        }

        public AbstractField SurfaceCloudField
        {
            get { return _cloudField; }
        }

        protected override void UpdateBitmap(
            IMapFieldView field,
            bool force)
        {
            Fill = SurfaceFieldRenderer.CreateBrush(field);
        }

        protected override bool CanZoom()
        {
            return false;
        }

    }

}
